<template>
  <div>
    <el-drawer
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose">
        <mavon-editor v-if="status === 'edit'"></mavon-editor>
        <div v-if="status === 'browse'" v-html="tableData[0].address" ></div>
    </el-drawer>

      <el-table 
      :data="tableData"
      border
      style="width: 800px">
      <el-table-column
        fixed
        prop="date"
        label="日期"
        width="150">
      </el-table-column>
      <el-table-column
        prop="title"
        label="文章"
        width="250">
      </el-table-column>
      <el-table-column
        prop="label"
        label="标签"
        width="120">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="150">
        <!-- <template slot-scope="scope"> -->
          <!-- <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button> -->
          <el-button  size="small" @click="browse" type="text" style="" ><i class="el-icon-view el-icon--right"></i> 浏览</el-button>
          <el-button  size="small" @click="edit" type="text" style="" icon="el-icon-edit">编辑</el-button>
          <el-button
            @click.native.prevent="deleteRow(scope.$index, tableData)"
            type="text"
            size="small"
            >
            <i class="el-icon-delete"></i>
            移除
          </el-button>
        <!-- </template> -->
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default 
{
  data() {
    return {
      visible: true,
      browseCount: 0,
      status: '',
      drawer: false,
      direction: 'rtl',
      tableData: 
      [
        {
        date: '2016-05-02',
        title: '**上海市普陀区金沙江路 1518 弄**',
        label: '上海',
        },
      ]
    };
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
        this.status = ''
    },
    browse()
    {
      this.drawer = true
      this.status = 'browse'
      if(this.browseCount == 0)
      {
        var MarkdownIt= require("markdown-it")
        var md = new MarkdownIt()
        var result = md.render(this.tableData[0].address)
        this.tableData[0].address = result
        this.browseCount++
      }
    },
    edit()
    {
      this.drawer = true
      this.status = 'edit'
    },  
    deleteRow(index, rows) {
        rows.splice(index, 1);
      }
  }
}
</script>

<style>
  .deletebtn
  {
    margin-left: 8px !important;
  }
</style>